<?php


        /*  
         * ======================================================================================
         * 
         * ALL the Zend_Forms classes performed by Jean Carlo Machado has the following scope:
         * 
         * public function init(); 
         * public function showForm($name,$destinationUrl);
         * 
         * The first one serves only to zend authenticate the fom         * 
         * The second one serves to show the form without use Zend patters
         * of forms. 
         * 
         * =======================================================================================
         * To call on the controllers or helpers scope:
         * 
         *      To show:
         *              require_once APPLICATION_PATH . '/forms/Forms_CriarNodo.php';
                        $form = new Forms_CriarNodo();
                        $form->setAction($this->_helper->url('recivecreatenod'));
                        $form->showForm('create','/nodo/recivecreatenod');
         * 
         *      To pick back (IN THE ACTION PASSED TO SHOW FORM):
         *                  require_once APPLICATION_PATH . '/forms/Forms_CriarNodo.php';
                            $form = new Forms_CriarNodo();

                            if($this->getRequest()->isPost())
                            {
                                $data = $this->_request->getPost();

                                print_r($data);

                                if($form->isValid($data))
                                {
                                   //DO SOMETHING
                                }
                                else
                                {
                                     $this->view->message = 'Dados Invalidos';
                                }
         * =========================================================================================
         * 
         */

class Forms_CriarArtigo extends Zend_Form {
    
    public function init()
    {
        /* The elements are the following
         * editablility (select)
         * title (text)
         * editor (complex)
         * bibliografy(text)
         * add (button)
         * create (button)
         */
        
        $this->setMethod("POST");
        
        $editability = new Zend_Form_Element_Select('editability');
        $editability->setLabel("Editabilidade");
        $editability->addMultiOptions(array('public' => "Publico",'private' => "Privado"));
        
        $title = $this->createElement('text','title',array("label" => "Titulo"));
        $title->setRequired(true)
                ->addValidator('alnum')
                ->addValidator('stringLength',true,array(6,20));
        
        $editor = new Zend_Form_Element_Textarea('editor');
        $editor->setLabel("Editor");
        $editor//->addValidator('alnum')
                ->addValidator('stringLength',true,array(6,100000000000));
        
        $bibliografy = $this->createElement('text','bibliograpy',array('label'=>"Bibliografia"));
//        $bibliografy->setRequired(true)
//                    ->addValidator('alnum')
//                    ->addValidator('stringLength',true,array(6,20));
//        
        $addBibliografy = new Zend_Form_Element_Button('addBibliograpy');
        $addBibliografy->setLabel('Adicionar');
        
        $this->addElement($editability);
        $this->addElement($title);
        $this->addElement($bibliografy);
        $this->addElement($addBibliografy);
        $this->addElement('submit','commit',array('label'=>'Criar'));
    }
    
    public function showForm($name,$destinationUrl)
    {
        $content = "<form name='$name' method='post' action='$destinationUrl'>";
        $content.= "<br>Editabilidade: <select name='editability'>";
        $content.= "<option value='public'>Publico";
        $content.= "<option value='private'>Privado";
        $content.= "</select>";
        $content.= "<br>Titulo: <input type='text' name='title' value=''><br>";
        /*EDITOR*/
        $content.= "<textarea name='editor'></textarea>";
        /* FINISH EDITOR */
        $content.= "<br>Bibliografia: <input type='text' name='bibliograpy' value=''>";
        $content.= "<input type='button' name='addBibliograpy' value='Adiconar'><br>";
        $content.= "<input type='submit' name='commit' value='Criar'>";
        $content.= "</form>";
        
        echo $content;
    }
    
}

?>
